//引入二次封装的axios
import request from "@/utils/request";
//引入接口类型
import type { reqRoleResponese, reqRoleMenuResponeseData } from "./type";
//枚举地址
enum API {
  //获取所有职位接口
  GET_ALL_POSITION = "/admin/acl/role/",
  //新增职位接口
  ADD_POSITION = "/admin/acl/role/save",
  //修改职位接口
  UPDATE_POSITION = "/admin/acl/role/update",
  //根据用户id获取职位权限数据
  GET_POSITION_BY_USER_ID = "/admin/acl/permission/toAssign/",
  //给对应的角色分配权限
  ASSIGN_POSITION = "/admin/acl/permission/doAssign/?",
  //删除职位接口
  DELETE_POSITION = "/admin/acl/role/remove/",
}

//获取所有职位的接口{page}/{limit}
export const getAllPosition = (page: number, limit: number, roleName: string) =>
  request.get<any, reqRoleResponese>(
    API.GET_ALL_POSITION + `${page}/${limit}/?roleName=${roleName}`,
  );
//修改或者添加职位接口
export const addOrUpdatePosition = (data: any) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATE_POSITION, data);
  } else {
    return request.post<any, any>(API.ADD_POSITION, data);
  }
};
//根据用户id获取所有职位权限数据
export const getPositionByUserId = (roleId: number) =>
  request.get<any, reqRoleMenuResponeseData>(
    API.GET_POSITION_BY_USER_ID + roleId,
  );
//给对应的角色分配权限
export const assignPosition = (roleId: number, permissionId: number[]) =>
  request.post<any, any>(
    API.ASSIGN_POSITION + `roleId=${roleId}&permissionId=${permissionId}`,
  );
//删除对应的职位
export const deletePostion = (id: number) =>
  request.delete<any, any>(API.DELETE_POSITION + id);
